$(document).ready(function()
{
	$(".stripe tr").mouseover(function()
	{
		$(this).addClass("over");
	}).mouseout(function()
	{
		$(this).removeClass("over");
	});
	$(".stripe tr:even").addClass("even");
	$(".stripe tr:odd").addClass("odd");

	$(".toolbox a").mouseover(function()
	{
		$(this).addClass("over");
	}).mouseout(function()
	{
		$(this).removeClass("over");
	});

	$("#allkey").append(
		$("<input type=\"checkbox\" />").click(function()
		{
			$("#bibtable :checkbox[name=key]").attr("checked", $(this).attr("checked"));
		}
	));
	$("#bibtable tbody :checkbox").click(function()
	{
		var count = $("#bibtable tbody :checkbox").length;
		var checkedCount = $("#bibtable tbody :checked").length;
		$("#allkey :checkbox").attr("checked", count == checkedCount);
	});

	$("a.bookmark").click(function()
	{
		var self = $(this);
		var href = $(this).attr("href");
		var fragment = href.substring(1).split("/");
		var uri = fragment[0];
		var key = fragment[1];

		var currentIcon = $(this).children("img").attr("src");
		var nextHref, nextIcon, nextAlt;
		if (uri == "bookmark")
		{
			nextHref = "/unbookmark/" + key;
			nextIcon = "/themes/default/icons/bookmark.png";
			nextAlt = "Click to bookmark";
		} else
		{
			nextHref = "/bookmark/" + key;
			nextIcon = "/themes/default/icons/unbookmark.png";
			nextAlt = "Click to unbookmark";
		}
		$.ajax( {
		type : "POST",
		url : href,
		success : function()
		{
			self.attr("href", nextHref);
			self.children("img").attr("src", nextIcon);
			self.children("img").attr("alt", nextAlt);
		}
		});
		return false;
	});
});
